﻿var fnCustomReport = function () {    
    parent.addTabs("CRM报表", encodeURI("../../Reports/ReportView.aspx?entity=V_CrmValueRpt&condition=" + const_Condition));
}
//备注过滤
var fnExplain = function (elCell, oRecord, oColumn, sData) {
    sData.replace("[BR]", "");
    if (sData.length > 20) {
        elCell.innerHTML = sData.substring(0, 20) + "..." + "<a href='javascript:CustomDbClick()'>详细</a>";
    }
    else {
        elCell.innerHTML = sData;
    }
};
//未签到原因
var fnUnSign = function (elCell, oRecord, oColumn, sData) {
    sData.replace("[BR]", "");
    if (sData.length > 20) {
        elCell.innerHTML = sData.substring(0, 20) + "..." + "<a href='javascript:CustomDbClick()'>详细</a>";
    }
    else {
        elCell.innerHTML = sData;
    }
};
//亮点分享过滤
var fnShare = function (elCell, oRecord, oColumn, sData) {
    sData.replace("[BR]", "");
    if (sData.length > 20) {
        elCell.innerHTML = sData.substring(0, 20) + "..." + "<a href='javascript:CustomDbClick()'>详细</a>";
    }
    else {
        elCell.innerHTML = sData;
    }
};
//格式化0
var fnZero = function (elCell, oRecord, oColumn, sData) {
   
    if (sData=="0") {
        elCell.innerHTML ="";
    }
    else {
        elCell.innerHTML = sData;
    }
};

//自动义双击方法
function CustomDbClick() {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    var vid = record.getData("WorkFlowInsId");
    if (vid != "") {
        window.parent.$("#tabs").tabs('close', '查看价值业绩申请单信息');
        var pagetitle = "查看价值业绩申请单信息";
        parent.addTabs(pagetitle, '../Crm/Modules/CrmValueTask.aspx?r=' + Math.random() + '&view=checks&descript=nxqd&flag=1&entity=CrmValue&WorkflowInsId=' + vid + '&title=' + encodeURI(pagetitle));
        parent.NeedRefreshPage = this;
    }
}
//新增按钮
function fnAddGain() {
    window.parent.$("#tabs").tabs('close', '提交申请');
    var pagetitle = "提交申请";
    parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?title=&WorktaskId=8d8b2429-8e5d-46cf-b231-824ce7503858&WorkflowId=e95c4f08-8786-4b82-b45d-3282b0d80338');
    parent.NeedRefreshPage = this;
}

////修改操作
//function fnEditGain() {
//    window.parent.$("#tabs").tabs('close', '修改价值业绩申请单'); 
//    var pagetitle = "修改价值业绩申请单";
//    var recordID = myDataTable.getSelectedRows()[0];
//    record = myDataTable.getRecord(recordID);
//    var vid = record.getData("WorkTaskInsId");
//    var vfid = record.getData("WorkFlowInsId");
//    if (vid != "") {
//        parent.addTabs(pagetitle, '../Crm/Modules/CrmValueTask.aspx?flag=1&view=0&descript=nxja&WorktaskId=955a8b81-234a-4eb7-b41f-4ed31e36f02d&WorkflowInsId=' + vfid + '&entity=CrmValue&WorktaskInsId=' + vid + '&title=OperStatus=0&WorkflowId=68f6a12b-b570-47ec-9808-51302693a546&statues=1');
//        parent.NeedRefreshPage = this;
//    }
//}
//自定义修改方法
var fnCustomEdit = function () {


    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null || record.getData("DState") != "结案") {
        alert("请选择一条状态为结案的数据");
        return;
    }
    window.parent.$("#tabs").tabs('close', '修改价值业绩申请单');
    var pagetitle = "修改价值业绩申请单";

    var vid = record.getData("WorkTaskInsId");
    var vfid = record.getData("WorkFlowInsId");
    if (vid != "") {
        parent.addTabs(pagetitle, '../Crm/Modules/CrmValueTask.aspx?flag=1&view=0&descript=nxja&WorkflowInsId=' + vfid + '&entity=CrmValue&WorktaskInsId=' + vid + '&title=OperStatus=0&statues=1');
        parent.NeedRefreshPage = this;
    }
}
//删除价值业绩
var fnCustomDeleteData = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条数据");
        return;
    }   
    var vid = record.getData("ID");
    if (vid != "") {
        var SaveUrl = "../Extend/AjaxData/CustomOperating.aspx?r=" + Math.random() + "&action=delete&entity=CrmValue&json=&type=0&id=" + vid;
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        YAHOO.example.container.dialog3.hide();
                        alert("删除成功!");
                        RefreshData();
                        return;
                    } else {
                        alert(str);
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
}
//后续业绩沉淀时间
var fnHxMonth = function (elCell, oRecord, oColumn, sData) {
    var vTemp = oRecord.getData("ValueType");
    if (vTemp == "后续业绩" && sData != "0") {
        elCell.innerHTML = sData;
    } else {
        elCell.innerHTML = "";
    }
};
//持续业绩沉淀时间
var fnCxMonth = function (elCell, oRecord, oColumn, sData) {
    var vTemp = oRecord.getData("ValueType");
    if (vTemp == "持续业绩" && sData!="0") {
        elCell.innerHTML = sData;
    } else {
        elCell.innerHTML = "";
    }
};
//格式化时间
var fnDate = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0001-01-01 ") {
        elCell.innerHTML = "";
    } else {
        elCell.innerHTML = sData;
    }
};